<script setup>
import {onBeforeUnmount,ref} from 'vue';
import emitter from '@/utils/bus';

let message = ref()

emitter.on('sendDataTo1',data=>{
    message.value = data.msg
})

onBeforeUnmount(()=>{
    emitter.off('sendDataTo1')
})

</script>

<template>

    <div>
        <h2>组件1</h2>
        <p>收到的消息：{{message}}</p>
    </div>

</template>

<style scoped>

</style>
